#ifndef AUTOPILOT_COM_H
#define AUTOPILOT_COM_H

#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include "message_types.h"
#include "message_defines.h"

/*!@brief This function returns the type number of the next packet
 *
 * @param socket The socket to get the message from
 *
 * This function should be called to get the type of next message. It should be
 * called to determine which function should be used to get the message.
 */
uint32_t get_message_type(int socket);

/*!@brief Flushes a simple packet from the socket.
 *
 * @param socket The socket to flush
 * @return nothing
 *
 * A simple packet is a packet that has no data associated with it.
 */
void socket_flush(int socket);

/*!@brief Send a flyto packet on the socket provided
 *
 * @param socket The socket to send the packet on
 * @param address The address of the autopilot program
 * @param packet The information that will be prepaired and sent
 * @return zero on success non-zero on failure
 * 
 * This function will prepare and send the packet in packet. Returns zero
 * on success non-zero on failure.
 */
int send_msg_flyto(int socket, struct sockaddr* address, msg_flyto* packet);

/*!@brief Gets the msg_state packet from the socket provided
 *
 * @param socket The socket that the message is receved from
 * @param message A pointer to a msg_state structure to be filled with data
 * @return zero on success non-zero on failure
 *
 * This function gets a msg_state packet off the socket provided. It handles 
 * changing the data to the proper byte ordering for use. Returns zero on success
 * non-zero on failure
 */
int get_msg_state(int socket, msg_state* message);

/*!@brief Gets the msg_desired_pos packet from the socket provided
 *
 * @param socket The socket that the message is receved from
 * @param message A pointer to a msg_desired_pos structure to be filled with data
 * @return zero on success non-zero on failure
 *
 * This function gets a msg_desired_pos packet off the socket provided. It handles
 * changing the data to the proper byte ordering for use. Returns zero on success
 * non-zero on failure.
 */
int get_msg_desired_pos(int socket, msg_desired_pos* message);

#endif
